package com.example.PullGame;


import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;


import com.example.wonderfulradish.Choose_Game;
import com.example.wonderfulradish.PagerViewAdapter;
import com.example.wonderfulradish.R;

import java.util.ArrayList;
import java.util.List;


public class StartPullActivity extends AppCompatActivity implements View.OnClickListener{

    private ViewPager viewPager;
    private ArrayList<View> pageview;
    private PagerViewAdapter mPagerAdapter;
    private Button bluestart ,greenstart, orangestart,purplestart,redstart,yellowstart,redback;
    private final int RED=1;
    private final int BLUE=2;
    private final int ORANGE=3;
    private final int PURPLE=4;
    private final int GREEN=5;
    private final int YELLOW=6;
    int flag;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start_pull);

        //初始化viewPager
        viewPager=(ViewPager) findViewById(R.id.viewPager);

        //初始化子界面
        LayoutInflater inflater=getLayoutInflater();
        View redView=inflater.inflate(R.layout.red_radish,null);
        View blueView=inflater.inflate(R.layout.blue_radish,null);
        View orangeView=inflater.inflate(R.layout.orange_radish,null);
        View purpleView=inflater.inflate(R.layout.purple_radish,null);
        View yellowView=inflater.inflate(R.layout.yellow_radish,null);
        View greenView=inflater.inflate(R.layout.green_radish,null);

        //将分页显示装入View组中
        pageview=new ArrayList<View>();
        //添加想要切换的界面
        pageview.add(redView);
        pageview.add(blueView);
        pageview.add(purpleView);
        pageview.add(orangeView);
        pageview.add(greenView);
        pageview.add(yellowView);
        //数据适配器
        mPagerAdapter=new PagerViewAdapter(pageview);
        //绑定适配器
        viewPager.setAdapter(mPagerAdapter);

        //获取子view中的控件的id并为其添加监听事件
        redstart=(Button) redView.findViewById(R.id.redstart);
        redstart.setOnClickListener(this);
        redback=(Button) redView.findViewById(R.id.redback);
        redback.setOnClickListener(this);
        bluestart=(Button) blueView.findViewById(R.id.bluestart);
        bluestart.setOnClickListener(this);
        greenstart=(Button) greenView.findViewById(R.id.greenstart);
        greenstart.setOnClickListener(this);
        orangestart=(Button) orangeView.findViewById(R.id.orangestart);
        orangestart.setOnClickListener(this);
        purplestart=(Button) purpleView.findViewById(R.id.purplestart);
        purplestart.setOnClickListener(this);
        yellowstart=(Button) yellowView.findViewById(R.id.yellowstart);
        yellowstart.setOnClickListener(this);


    }

    @Override
    public void onClick(View v){
        switch (v.getId()) {
            case R.id.bluestart:
                flag=BLUE;
                Intent intent2=new Intent(StartPullActivity.this,PullGame.class);
                intent2.putExtra("color_data",flag);
                startActivity(intent2);
                finish();
                break;
            case R.id.greenstart:
                flag=GREEN;

                break;
            case R.id.orangestart:
                flag=ORANGE;

                break;
            case R.id.purplestart:
                flag=PURPLE;

                break;
            case R.id.redstart:
                flag=RED;
                Intent intent=new Intent(StartPullActivity.this,PullGame.class);
                startActivity(intent);
                break;
            case R.id.redback:
                Intent intent1=new Intent(StartPullActivity.this, Choose_Game.class);
                startActivity(intent1);
                finish();
            case R.id.yellowstart:
                flag=YELLOW;

                break;
            default:
                break;
        }
    }

}
